﻿<%@ page contentType="text/html; charset=UTF-8" language="java" pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head> 
    <title>会员登录 - 服务外包职业能力实训工程实验室平台</title>
    <link rel="stylesheet" href="${ctx}/static/css/login/css/login.css"/>
    
    <link href="${ctx}/static/ligerui/lib/ligerUI/skins/Aqua/css/ligerui-dialog.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/static/ligerui/lib/ligerUI/skins/Gray/css/dialog.css" rel="stylesheet" type="text/css" />
    
    <script src="${ctx}/static/ligerui/lib/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>
    <script src="${ctx}/static/ligerui/lib/ligerUI/js/core/base.js" type="text/javascript"></script>
    <script src="${ctx}/static/ligerui/lib/ligerUI/js/plugins/ligerDialog.js" type="text/javascript"></script>
    <script src="${ctx}/static/ligerui/lib/js/LG.js" type="text/javascript"></script>
    <script src="${ctx}/static/js/common.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function (){
        	if(window.frameElement && window.frameElement.tagName=="IFRAME"){
        		window.parent.location.href="${ctx}/login";
        	}
        	
            $(document).keydown(function (e)
            {
                if (e.keyCode == 13)
                {
                    dologin();
                }
            });

            $("#btnLogin").click(function ()
            {
                dologin();
            });
             $("#kaptchaImage").click(function () {
                	$(this).hide().attr('src', '${ctx}/captcha/verify?' + Math.floor(Math.random()*100) ).fadeIn(); 
                }
            );  
        });
        
        function dologin(){
            var username = $("#txtUsername").val();
            var password = $("#txtPassword").val();
            var verifyCode=$("#verifyCode").val();
            
            if (username == ""){
                alert('账号不能为空!');
                $("#txtUsername").focus();
                return;
            }
            if (password == ""){
                alert('密码不能为空!');
                $("#txtPassword").focus();
                return;
            }
            if (verifyCode == ""){
                alert('验证码不能为空!');
                $("#verifyCode").focus();
                return;
            }
            
            $.ajax({
                type: 'post', cache: false, dataType: 'json',
                url: '${ctx}/login',
                data: [
                { name: 'userId', value: username },
                { name: 'password', value: password },
                { name:'verifyCode',value:verifyCode}
                ],
                success: function (result){
                	
                	if(typeof(result)=="string"){
                		result=eval("("+result+")");
                	}
                    if (!result.success){
                        alert(result.message);
                        return;
                    } else{
                    	if(result.data.userType=="stu"){
                    	 	window.location.href="${ctx}/studentHome";
                    	}else{
                    		window.location.href ="${ctx}/main";
                    	}
                    }
                },
                error: function (){
                    alert('系统错误,请与系统管理员联系!');
                },
                beforeSend: function (){
                    $.ligerDialog.waitting("正在登陆中,请稍后...");
                    $("#btnLogin").attr("disabled", true);
                },
                complete: function (){
                    $.ligerDialog.closeWaitting();
                    $("#btnLogin").attr("disabled", false);
                }
            });
        }
        
/*         function changeCaptcha(){
        	$("#kaptchaImage").hide().attr('src', '${ctx}/captcha/verify?' + Math.floor(Math.random()*100) ).fadeIn(); 
        } */
    </script>
</head>
<body>
  <div class="page">
    <h1 class="login-header auto">
      	服务外包职业能力实训工程实验室平台
    </h1>
    <div class="login-form-wrap auto">
      <h2>会员登录</h2>
      <form action="" method="post" class="login-form">
        <div class="form-row">
          <label class="form-label">用户名：</label>
          <input name="userId" id="txtUsername" value=""/>
        </div>
        <div class="form-row">
          <label class="form-label">密码：</label>
          <input type="password" name="password" id="txtPassword" value=""/>
        </div>
        <div class="form-row rel">
          <label class="form-label">验证码：</label>
          <input type="text" name="verifyCode" id="verifyCode" class="captcha-input"/>
          <img src="${ctx}/captcha/verify" id="kaptchaImage" class="captcha-img"/>
<!--           <a class="captcha-refresh abs" href="javascript:void(0);" onclick="changeCaptcha();">看不清<br/>换一张</a> -->
        </div>
        <div class="form-action">
          <label class="form-label"> </label>
          <button type="button" id="btnLogin">登陆</button>
          <!-- <a href="">马上注册!</a> -->
        </div>
      </form>
    </div> <!-- .login-form-wrap -->
    <div class="footer">
      	版权所有 启秀科技（北京）有限公司
    </div>
  </div> <!-- .page END -->
</body>
</html>
